package org.apache.dubbo.registry.client.event;

import org.apache.dubbo.event.Event;
import org.apache.dubbo.registry.client.ServiceInstance;

import java.util.Collection;
import java.util.Collections;

/**
 * An event raised after the {@link ServiceInstance instances} of one service has been changed.
 *
 * @see ServiceInstancesChangedListener
 * @since 2.7.5
 */
public class ServiceInstancesChangedEvent extends Event {

    private final String serviceName;

    private final Collection<ServiceInstance> serviceInstances;

    /**
     * @param serviceName      The name of service that was changed
     * @param serviceInstances all {@link ServiceInstance service instances}
     * @throws IllegalArgumentException if source is null.
     */
    public ServiceInstancesChangedEvent(String serviceName,Collection<ServiceInstance> serviceInstances) {
        super(serviceName);
        this.serviceName = serviceName;
        this.serviceInstances = Collections.unmodifiableCollection(serviceInstances);
    }

    /**
     * @return The name of service that was changed
     */
    public String getServiceName() {
        return serviceName;
    }

    /**
     * @return all {@link ServiceInstance service instances}
     */
    public Collection<ServiceInstance> getServiceInstances() {
        return serviceInstances;
    }
}
